#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "passwd.h"
#include <mysql/mysql.h>
#include "userlist.h"
#include <QSplitter>
#include "common.h"
//#include "usercount.h"
#include "mailserver.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
   // m_movie(":/image/loading.gif")
{
    ui->setupUi(this);

    m_userlist = NULL;
    m_usercount = NULL;
    m_mailserver = NULL;
    m_cur = m_userlist;
    menuTriggered(ui->action_smtp);
    //setCentralWidget(m_userlist);
   // setLayout(&m_layout);
   // m_layout.addWidget(m_userlist);
    /*m_loading.setFrameStyle(Qt::FramelessWindowHint);
    m_loading.setMovie(&m_movie);
    m_movie.setBackgroundColor(Qt::black);
    if( m_movie.isValid() )
    {
       // m_movie.start();
        statusBar()->addWidget(&m_loading);

    }*/
   // m_loading.setText("test");
 }

MainWindow::~MainWindow()
{
    //mysql_close(&g_mysql);
    delete ui;
}

// menu click
void MainWindow::menuTriggered(QAction *action)
{
    if("action_exit" == action->objectName())
    {
        close();
    }
    else if("action_passwd" == action->objectName())
    {
        Passwd      pwd(this);

        pwd.exec();
    }
    else if("action_list" == action->objectName())
    {
        if(NULL == m_userlist || m_cur != m_userlist) m_userlist = new UserList;
        setCentralWidget(m_userlist);
        m_cur = m_userlist;
        setWindowTitle(_T("广告平台 - 用户列表"));
    }
    else if("action_count" == action->objectName())
    {
//        if(NULL == m_usercount || m_cur != m_usercount) m_usercount = new UserCount;
 //       setCentralWidget(m_usercount);
 //       m_cur = m_usercount;
 //       setWindowTitle(tr("广告平台 - 用户统计"));
    }
    else if("action_smtp" == action->objectName())
    {
        if(NULL == m_mailserver || m_cur != m_mailserver) m_mailserver = new MailServer;
        setCentralWidget(m_mailserver);
        m_cur = m_mailserver;
        setWindowTitle(_T("广告平台 - 邮件服务器"));
    }
}
